#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (int)b; ++i)
typedef pair<int, int> pi;
const int N = 1010;
bool vis[N][N];
int w[N][N];
int n;
int nhill, nvall;
const int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1},
          dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
void bfs(int xi, int yi) {
  if (vis[xi][yi]) return;
  bool has_higher = false, has_lower = false;
  queue<pi> q;
  q.emplace(xi, yi);
  vis[xi][yi] = true;

  while (q.size()) {
    auto [x, y] = q.front();
    q.pop();
    rep(i, 0, 8) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 || nx >= n || ny < 0 || ny >= n) continue;
      int ch = w[x][y], nh = w[nx][ny];
      if (ch > nh)
        has_higher = true;
      else if (ch < nh)
        has_lower = true;
      else if (!vis[nx][ny]) {  // 如果访问过，不入队
        q.emplace(nx, ny);
        vis[nx][ny] = true;
      }
    }
  }

  if (!has_lower) nhill++;
  if (!has_higher) nvall++;
}
int main() {
  cin >> n;
  rep(i, 0, n) rep(j, 0, n) cin >> w[i][j];
  rep(i, 0, n) rep(j, 0, n) bfs(i, j);

  cout << nhill << ' ' << nvall << endl;
}
